package com.fuhao.springbootrabbit.Service;

import com.fuhao.springbootrabbit.constant.RabbitConstant;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author zhang
 */
@Service
public class DirectService{

    @Autowired
    private RabbitTemplate rabbitTemplate;
    public DirectService(){
    }

    public void DirectSend(){
        Map<Object,String> map = new HashMap<>();
        map.put("username","张三");

        //构建回调返回的数据
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(RabbitConstant.DIRECT_EXCHANGE_NAME,RabbitConstant.DIRECT_ROUTE_KEY_NAME,map,correlationData);
    }

}
